package com.jquest.collision;

import org.newdawn.slick.geom.Shape;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Color;
import com.jquest.data.Renderable;
import com.jquest.data.AbstractEntity;

/**
 * Created by IntelliJ IDEA.
 * User: Johan
 * Date: 2009-dec-11
 * Time: 16:34:15
 * To change this template use File | Settings | File Templates.
 */
public class CollisionMask implements Collidable, Renderable {
    private Shape mask;
    private AbstractEntity owner;
    private int offsetX = 0;
    private int offsetY = 0;

    public static final boolean DEBUG = false;

    public CollisionMask(Shape mask, AbstractEntity owner) {
        this.mask = mask;
        this.owner = owner;
    }

    public void setOffset(int x, int y) {
        this.offsetX = x;
        this.offsetY = y;
    }

    public boolean collides(AbstractEntity e1) {
        if(e1.getX() == mask.getMinX() || e1.getX() == mask.getMaxX() || e1.getY() == mask.getMinY() || e1.getY() == mask.getMaxY()) {
            return true;
        } else return false;
    }

    public void update(int time) {
        mask.setCenterX(owner.getCenterX() + offsetX);
        mask.setCenterY(owner.getCenterY() + offsetY);
        //mask.setLocation(owner.getCenterX(), owner.getCenterY());
    }

    public void render(Graphics g, Object attachment) {
        if(DEBUG) {
            g.setColor(Color.red);
            g.fill(mask);
        }
    }

}
